package com.lagou.demo.controller;

import com.lagou.edu.mvcframework.annonatations.LgAutowired;
import com.lagou.edu.mvcframework.annonatations.LgController;
import com.lagou.edu.mvcframework.annonatations.LgRequestMapping;
import com.lagou.demo.service.DemoService;
import com.lagou.edu.mvcframework.annonatations.LgSecurity;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@LgController
@LgRequestMapping("/demo")
public class DemoController {

    @LgAutowired
    private DemoService demoService;

    @LgRequestMapping("/query")
    public String query(HttpServletRequest request, HttpServletResponse response,String name){
        String s = demoService.get(name);
        return s;
    }

    @LgSecurity({"admin1","admin2"})
    @LgRequestMapping("/admin")
    public String admin(HttpServletRequest request, HttpServletResponse response,String name){
        try {
            request.setCharacterEncoding("UTF-8");
            response.setContentType("text/html; charset=utf-8");
            response.getWriter().write("admin1/admin2:有权限");
        } catch (IOException e) {
            e.printStackTrace();
        }
        return "admin1/admin2:有权限,可以正常访问";
    }

    @LgSecurity({"admin3"})
    @LgRequestMapping("/admin3")
    public String admin3(HttpServletRequest request, HttpServletResponse response,String name) {
        try {
            response.setContentType("text/html; charset=utf-8");
            response.getWriter().write("admin3:有权限");
        } catch (IOException e) {
            e.printStackTrace();
        }
        return "admin3:有权限,可以正常访问";
    }

}
